package com.mayuanfei.springboot15.serializer;

import cn.hutool.extra.spring.SpringUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;
import com.mayuanfei.springboot15.pojo.UserInfo2;

import java.io.IOException;
import java.io.InputStream;

/**
 * TODO 类描述
 *
 * @author 老马
 * @date 2023-07-24 14:29
 */
public class UserInfo2Serializer implements StreamSerializer<UserInfo2> {

    @Override
    public int getTypeId() {
        return 100;
    }

    @Override
    public void write(ObjectDataOutput out, UserInfo2 object) throws IOException {
        ObjectMapper mapper = SpringUtil.getBean(ObjectMapper.class);
        out.write(mapper.writeValueAsBytes(object));
    }

    @Override
    public UserInfo2 read(ObjectDataInput in) throws IOException {
        InputStream inputStream = (InputStream) in;
        ObjectMapper mapper = SpringUtil.getBean(ObjectMapper.class);
        return mapper.readValue(inputStream, UserInfo2.class);
    }
}